﻿Partial Public Class ucActions

    Public Shared ReadOnly DeleteButtonClickedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("DeleteButtonClicked", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(ucActions))
    Public Custom Event DeleteButtonClicked As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(DeleteButtonClickedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(DeleteButtonClickedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event

    Public Shared ReadOnly CancelButtonClickedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("CancelButtonClicked", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(ucActions))
    Public Custom Event CancelButtonClicked As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(CancelButtonClickedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(CancelButtonClickedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event


    Public Shared ReadOnly AddButtonClickedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("AddButtonClicked", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(ucActions))
    Public Custom Event AddButtonClicked As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(AddButtonClickedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(AddButtonClickedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event

    Public Shared ReadOnly SaveButtonClickedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("SaveButtonClicked", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(ucActions))
    Public Custom Event SaveButtonClicked As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(SaveButtonClickedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(SaveButtonClickedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event

    Public Shared ReadOnly EditButtonClickedEvent As RoutedEvent = EventManager.RegisterRoutedEvent("EditButtonClicked", RoutingStrategy.Bubble, GetType(RoutedEventHandler), GetType(ucActions))
    Public Custom Event EditButtonClicked As RoutedEventHandler
        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(EditButtonClickedEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(EditButtonClickedEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event




    Private Sub ucActions_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        buttonSaveMain.IsEnabled = False
        'saveImage.Source = grayImage(saveImage).Source
        buttonCancelMain.IsEnabled = False
    End Sub

    Private Sub buttonEditMain_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonEditMain.Click
        buttonSaveMain.IsEnabled = True
        buttonEditMain.IsEnabled = False
        buttonAddMain.IsEnabled = False
        buttonDeleteMain.IsEnabled = False
        buttonCancelMain.IsEnabled = True
        RibbonMain.isDirty = True
        Dim args As New RoutedEventArgs(EditButtonClickedEvent)
        MyBase.RaiseEvent(args)

    End Sub

    Function grayImage(ByVal colorImage As Image) As Image
        Dim i As New Image
        Dim fcb As FormatConvertedBitmap = New FormatConvertedBitmap(colorImage.Source, PixelFormats.Gray32Float, Nothing, 0)
        i.Source = fcb
        Return i
    End Function

    Private Sub buttonAddMain_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonAddMain.Click
        buttonSaveMain.IsEnabled = True
        buttonEditMain.IsEnabled = False
        buttonAddMain.IsEnabled = False
        buttonDeleteMain.IsEnabled = False
        buttonCancelMain.IsEnabled = True
        RibbonMain.isDirty = True
        Dim args As New RoutedEventArgs(AddButtonClickedEvent)
        MyBase.RaiseEvent(args)
    End Sub

    Private Sub buttonSaveMain_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonSaveMain.Click
        buttonSaveMain.IsEnabled = False
        buttonEditMain.IsEnabled = True
        buttonAddMain.IsEnabled = True
        buttonDeleteMain.IsEnabled = True
        buttonCancelMain.IsEnabled = False
        RibbonMain.isDirty = False
        Dim args As New RoutedEventArgs(SaveButtonClickedEvent)
        MyBase.RaiseEvent(args)
    End Sub

    Private Sub buttonCancelMain_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonCancelMain.Click
        RibbonMain.isDirty = False
        buttonSaveMain.IsEnabled = False
        buttonEditMain.IsEnabled = True
        buttonAddMain.IsEnabled = True
        buttonDeleteMain.IsEnabled = True
        buttonCancelMain.IsEnabled = False
        Dim args As New RoutedEventArgs(CancelButtonClickedEvent)
        MyBase.RaiseEvent(args)
    End Sub

    Private Sub buttonDeleteMain_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles buttonDeleteMain.Click
        buttonSaveMain.IsEnabled = False
        buttonEditMain.IsEnabled = True
        buttonAddMain.IsEnabled = True
        buttonDeleteMain.IsEnabled = True
        buttonCancelMain.IsEnabled = False
        RibbonMain.isDirty = True
        Dim args As New RoutedEventArgs(DeleteButtonClickedEvent)
        MyBase.RaiseEvent(args)
    End Sub

    Private Sub buttonMain_IsEnabledChanged(ByVal sender As Object, ByVal e As System.Windows.DependencyPropertyChangedEventArgs) Handles buttonAddMain.IsEnabledChanged, buttonCancelMain.IsEnabledChanged, buttonDeleteMain.IsEnabledChanged, buttonEditMain.IsEnabledChanged, buttonSaveMain.IsEnabledChanged
        'If sender.IsEnabled Then
        '    sender.Background = Brushes.Transparent
        'Else
        '    sender.Background = Brushes.Beige
        'End If
    End Sub
End Class



